import {
	quitLogin
} from '@/utils/util.js'
export const ShareUrl = 'https://www.hfscmachine.com';
//export const ImageSeeUrl = 'https://www.sichuangscience.cn';//
export const ImageSeeUrl = 'https://www.hfscmachine.com';

// #ifdef APP-PLUS
export const BASEURL = ImageSeeUrl + '/hea';
// export const BASEURL = 'www.hfscmachine.com';
// #endif
// #ifdef MP-WEIXIN
export const BASEURL = ImageSeeUrl + '/hea';
//export const BASEURL = ImageSeeUrl;
// #endif
// #ifdef H5
export const BASEURL = '/hea';
// #endif


import {
	showLoading,
	hideLoading
} from '@/utils/toast.js';

export const post = function(url, data, method = 'post') {
	// showLoading();
	return new Promise((resolve, reject) => {
		uni.request({
			url: BASEURL + url,
			method,
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				//'content-type': 'application/json',
				userId: uni.getStorageSync('userId')
			},
			data: {
				...data
			},
			success: res => {
				// console.log(data);
				if (res.data.ret == 0) {
					resolve(res.data);
				} else if (res.data.ret == -1) {
					console.log('未登录！');
					reject(res.data);
					quitLogin();
				} else {
					reject(res.data);
				}
			},
			fail: err => {
				reject(err);
			},
			complete() {
				// hideLoading();
			}
		})
	})
}


export const get = function(url, data, method = 'GET') {
	// showLoading();
	return new Promise((resolve, reject) => {
		var postData = data;
		uni.request({
			url: BASEURL + url,
			method,
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				userId: uni.getStorageSync('userId')
			},
			data: postData,
			success: res => {
				//console.log(res);
				if (res.data.ret == 0) {
					resolve(res.data);
				} else if (res.data.ret == -1) {
					console.log('未登录！');
					reject(res.data);
					quitLogin();
				} else {
					reject(res.data);
				}
			},
			fail: err => {
				reject(err);
			},
			complete() {
				// hideLoading();
			}
		})
	})
}

